package roslan.musicbox.crawler;

import java.io.IOException;
import java.text.ParseException;

import org.farng.mp3.TagException;

import com.enterprisedt.net.ftp.FTPException;

public class CrawlerThread extends Thread{
	private String host;
	private String initPath;
	private boolean last;
	private FTPMusicTagCrawler crawler;
	
	public void setHost(String host){
		this.host = host;
	}
	
	public void setInitPath(String path){
		this.initPath = path;
	}
	
	public void setLast(boolean last){
		this.last = last;
	}
	
	public void setCrawler(FTPMusicTagCrawler crawler){
		this.crawler = crawler;
	}
	
	public void run(){
		crawler.setRemoteHost(host);
		crawler.setInitPath(initPath);
		crawler.setLast(last);
		try {
			crawler.startCrawl();
		} catch (FTPException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (TagException e) {
			e.printStackTrace();
		}
	}
	
	public void setStop(){
		crawler.setStopped();
		while(this.isAlive()){}
	}
	
	public void end(){
		try {
			crawler.endCrawl();
		} catch (FTPException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
}
